﻿using System.Text;
using UnityEditor;
using UnityEngine;

public class GetDependenciesExample : MonoBehaviour
{
    [MenuItem("APIExamples/GetDependencies")]
    static void GetAllDependenciesForScenes()
    {
        var allScenes = AssetDatabase.FindAssets("t:Prefab");
        string[] allPaths = new string[allScenes.Length];
        int curSceneIndex = 0;

        foreach (var guid in allScenes)
        {
            var path = AssetDatabase.GUIDToAssetPath(guid);
            allPaths[curSceneIndex] = path;
            ++curSceneIndex;
        }

        var dependencies = AssetDatabase.GetDependencies(allPaths[4]);

        StringBuilder dependenciesString = new StringBuilder();
        dependenciesString.AppendLine();

        foreach (var curDependency in dependencies)
        {
            dependenciesString.Append(curDependency);
            dependenciesString.AppendLine();
        }

        Debug.Log("All dependencies for Scenes in Project: " + dependenciesString);
    }
}